<?php  //UTF-8
 /* operating (use only that) */
  function SELECT($patch, $user_n, $value) {
    switch($patch) {
      case '243'  : return false;
      case '322'  : 
      case '322a' : return get_322($user_n, $value);
      case '332'  : return false;
      case '333'  : return false;
      case '335'  : return false;
      default     : return false;
    }
  }
  
  function get_values($patch) {
    switch($patch) {
      case '243'  : return false;
      case '322'  :
      case '322a' : return get_val322(); break;
      case '332'  : return false;
      case '333'  : return false;
      case '335'  : return false;
      default     : return false;
    }
  }
 
 /* 3.2.2a */ 
  function get_322($user_name, $value) {
    $usr_id = get_usr_id($user_name);
    if(!$usr_id)
      return false;
    
    if      ($value == 0) {
      $res = get_usr_data($usr_id, 296);
      if($res !== false)
        return sprintf(title322($res), $user_name);
      else
        return false;
      
    } elseif($value == 1) {
      if($dat = get_usr_record($usr_id))
        return 'Level '.$dat['level'];
      else
        return false;
        
    } elseif($value == 2) {
      if($dat = get_usr_record($usr_id))
        return race322($dat['race']);
      else
        return false;
        
    } elseif($value == 3) {
      if($dat = get_usr_record($usr_id))
        return class322($dat['class']);
      else
        return false;
        
    } elseif($value == 4) {
      if($dat = get_usr_record($usr_id))
        return race322($dat['race']).' '.class322($dat['class']);
      else
        return false;
        
    } elseif($value == 5) {
      $guild = get_usr_data($usr_id, 151);
      if($guild === false) return false;
      
      $return = @mysql_query('SELECT `name` FROM `'.DB_CHR.'`.`guild` WHERE `guildid`=\''.$guild.'\' LIMIT 1');
      $guild = @mysql_fetch_assoc($return);
      return '<'.$guild['name'].'>';
      
    } elseif($value == 6) {
      if($dat = get_usr_record($usr_id))
        return 'Money: '.convert_gold($dat['money']);
      else
        return false;
        
    } elseif($value == 7) {
      if($dat = get_usr_record($usr_id))
        return map322($dat['map']);
      else
        return false;
        
    } elseif($value == 8) {
      if($dat = get_usr_record($usr_id))
        if($dat['online'] == 1)
          return 'Is Online';
        else
          return 'Is Offline';
      else
        return false;
        
    } elseif($value == 9) {
      if($dat = get_usr_record($usr_id))
        return 'Played: '.convert_date($dat['totaltime']);
      else
        return false;
    
    } elseif($value == 10) {
      $HP = get_usr_data($usr_id, 23);
      if($HP !== false)
        return $HP.'HP';
      else
        return false;
      
    } elseif($value == 11) {
      $MHP = get_usr_data($usr_id, 31);
      if($MHP !== false)
        return 'Max: '.$MHP.'HP';
      else
        return false;
      
    } elseif($value == 12) {
      $HP = get_usr_data($usr_id, 23);
      $MHP = get_usr_data($usr_id, 31);
      if(($HP !== false) || ($MHP !== false))
        return $HP.'HP / '.$MHP.'HP';
      else
        return false;
      
    } elseif($value == 13) {
      $MP = get_usr_data($usr_id, 24);
      if($MP !== false)
        return $MP.'Mana';
      else
        return false;
      
    } elseif($value == 14) {  
      $MMP = get_usr_data($usr_id, 32);
      if($MMP !== false)
        return 'Max: '.$MMP.'Mana';
      else
        return false;
      
    } elseif($value == 15) {
      $MP = get_usr_data($usr_id, 24);
      $MMP = get_usr_data($usr_id, 32);
      if(($MP !== false) || ($MMP !== false))
        return $MP.'Mana / '.$MMP.'Mana';
      else
        return false;
      
    } elseif($value == 16) {
      $HP = get_usr_data($usr_id, 23);
      $MP = get_usr_data($usr_id, 24);
      if(($HP !== false) || ($MP !== false))
        return $HP.'HP / '.$MP.'Mana';
      else
        return false;
      
    } elseif($value == 17) {
      $MHP = get_usr_data($usr_id, 31);
      $MMP = get_usr_data($usr_id, 32);
      if(($MHP !== false) || ($MMP !== false))
        return 'Max: '.$MHP.'HP / '.$MMP.'Mana';
      else
        return false;
      
    } else {
      return false;
      
    }
  }
  
  function get_val322() {
    $val[1] = 'Level';
    $val[]  = 'Race';
    $val[]  = 'Class';
    $val[]  = 'Race-Class';
    $val[]  = 'Guild'; //5
    $val[]  = 'Money';
    $val[]  = 'Map';
    $val[]  = 'Online';
    $val[]  = 'Played';
    $val[]  = 'Health'; //10
    $val[]  = 'Max HP';
    $val[]  = 'HP / Max HP';
    $val[]  = 'Mana';
    $val[]  = 'Max Mana';
    $val[]  = 'Mana / Max'; //15
    $val[]  = 'HP / Mana';
    $val[]  = 'Max HP / Mana'; //17
    
    return $val;
  }
  
  function race322($race) {
    switch ($race) {
      case 1 : return 'Human';
      case 2 : return 'Orc';
      case 3 : return 'Dwarf';
      case 4 : return 'Night Elf';
      case 5 : return 'Undead';
      case 6 : return 'Tauren';
      case 7 : return 'Gnome';
      case 8 : return 'Troll';
      case 9 : return 'Draenei';
      case 10: return 'Blood Elf';
      default: return 'Unknown Race';
    }
  }
  
  function class322($class) {
    switch ($class) {
      case 1 : return 'Warrior';
      case 2 : return 'Paladin';
      case 3 : return 'Hunter';
      case 4 : return 'Rogue';
      case 5 : return 'Priest';
      case 6 : return 'Death Knight';
      case 7 : return 'Shaman';
      case 8 : return 'Mage';
      case 9 : return 'Warlock';
      case 11: return 'Druid';
      default: return 'Unknown Class';
    }
  }
  
  function title322($TitleId) {
    switch ($TitleId) {
      case 0  : return '%s';
      case 1  : return 'Private %s';
      case 2  : return 'Corporal %s';
      case 3  : return 'Sergeant %s';
      case 4  : return 'Master Sergeant %s';
      case 5  : return 'Sergeant Major %s';
      case 6  : return 'Knight %s';
      case 7  : return 'Knight-Lieutenant %s';
      case 8  : return 'Knight-Captain %s';
      case 9  : return 'Knight-Champion %s';
      case 10 : return 'Lieutenant Commander %s';
      case 11 : return 'Commander %s';
      case 12 : return 'Marshal %s';
      case 13 : return 'Field Marshal %s';
      case 14 : return 'Grand Marshal %s';
      case 15 : return 'Scout %s';
      case 16 : return 'Grunt %s';
      case 17 : return 'Sergeant %s';
      case 18 : return 'Senior Sergeant %s';
      case 19 : return 'First Sergeant %s';
      case 20 : return 'Stone Guard %s';
      case 21 : return 'Blood Guard %s';
      case 22 : return 'Legionnaire %s';
      case 23 : return 'Centurion %s';
      case 24 : return 'Champion %s';
      case 25 : return 'Lieutenant General %s';
      case 26 : return 'General %s';
      case 27 : return 'Warlord %s';
      case 28 : return 'High Warlord %s';
      case 29 : return 'Gladiator %s';
      case 30 : return 'Duelist %s';
      case 31 : return 'Rival %s';
      case 32 : return 'Challenger %s';
      case 33 : return 'Scarab Lord %s';
      case 34 : return 'Conqueror %s';
      case 35 : return 'Justicar %s';
      case 36 : return '%s, Champion of the Naaru';
      case 37 : return 'Merciless Gladiator %s';
      case 38 : return '%s of the Shattered Sun';
      case 39 : return '%s, Hand of A\'dal';
      case 40 : return 'Vengeful Gladiator %s';
      case 41 : return 'Battlemaster %s';
      case 43 : return 'Elder %s';
      case 44 : return 'Flame Warden %s';
      case 45 : return 'Flame Keeper %s';
      case 46 : return '%s the Exalted';
      case 47 : return '%s the Explorer';
      case 48 : return '%s the Diplomat';
      case 49 : return 'Brutal Gladiator %s';
      case 42 : return '%s the Seeker';
      case 50 : return 'Arena Master %s';
      case 51 : return 'Salty %s';
      case 52 : return 'Chef %s';
      case 53 : return '%s the Supreme';
      case 54 : return '%s of the Ten Storms';
      case 55 : return '%s of the Emerald Dream';
      case 57 : return 'Prophet %s';
      case 58 : return '%s the Malefic';
      case 59 : return 'Stalker %s';
      case 60 : return '%s of the Ebon Blade';
      case 61 : return 'Archmage %s';
      case 62 : return 'Warbringer %s';
      case 63 : return 'Assassin %s';
      case 64 : return 'Grand Master Alchemist %s';
      case 65 : return 'Grand Master Blacksmith %s';
      case 66 : return 'Iron Chef %s';
      case 67 : return 'Grand Master Enchanter %s';
      case 68 : return 'Grand Master Engineer %s';
      case 69 : return 'Doctor %s';
      case 70 : return 'Grand Master Angler %s';
      case 71 : return 'Grand Master Herbalist %s';
      case 72 : return 'Grand Master Scribe %s';
      case 73 : return 'Grand Master Jewelcrafter %s';
      case 74 : return 'Grand Master Leatherworker %s';
      case 75 : return 'Grand Master Miner %s';
      case 76 : return 'Grand Master Skinner %s';
      case 77 : return 'Grand Master Tailor %s';
      case 78 : return '%s of Quel\'Thalas';
      case 79 : return '%s of Argus';
      case 80 : return '%s of Khaz Modan';
      case 81 : return '%s of Gnomeregan';
      case 82 : return '%s the Lion Hearted';
      case 83 : return '%s, Champion of Elune';
      case 84 : return '%s, Hero of Orgrimmar';
      case 85 : return 'Plainsrunner %s';
      case 86 : return '%s of the Darkspear';
      case 87 : return '%s the Forsaken';
      case 88 : return '%s the Magic Seeker';
      case 89 : return 'Twilight Vanquisher %s';
      case 90 : return '%s, Conqueror of Naxxramas';
      case 91 : return '%s, Hero of Northrend';
      case 92 : return '%s the Hallowed';
      case 93 : return 'Loremaster %s';
      case 94 : return '%s of the Alliance';
      case 95 : return '%s of the Horde';
      case 96 : return '%s the Flawless Victor';
      case 97 : return '%s, Champion of the Frozen Wastes';
      case 98 : return 'Ambassador %s';
      case 99 : return '%s the Argent Champion';
      case 100: return '%s, Guardian of Cenarius';
      case 101: return 'Brewmaster %s';
      case 102: return 'Merrymaker %s';
      case 103: return '%s the Love Fool';
      case 104: return 'Matron %s';
      case 105: return 'Patron %s';
      case 106: return 'Obsidian Slayer %s';
      case 107: return '%s of the Nightfall';
      case 108: return '%s the Immortal';
      case 109: return '%s the Undying';
      case 110: return '%s Jenkins';
      case 111: return 'Bloodsail Admiral %s';
      case 112: return '%s the Insane';
      case 113: return '%s of the Exodar';
      case 114: return '%s of Darnassus';
      case 115: return '%s of Ironforge';
      case 116: return '%s of Stormwind';
      case 117: return '%s of Orgrimmar';
      case 118: return '%s of Sen\'jin';
      case 119: return '%s of Silvermoon';
      case 120: return '%s of Thunder Bluff';
      case 121: return '%s of the Undercity';
      case 122: return '%s the Noble';
      case 123: return 'Crusader %s';
      case 56 : return 'Deadly Gladiator %s';
      case 124: return '%s, Death\'s Demise';
      case 125: return '%s the Celestial Defender';
      case 126: return '%s, Conqueror of Ulduar';
      case 127: return '%s, Champion of Ulduar';
      case 128: return 'Vanquisher %s';
      case 129: return 'Starcaller %s';
      case 130: return '%s the Astral Walker';
      case 131: return '%s, Herald of the Titans';
      case 132: return 'Furious Gladiator %s';
      case 133: return '%s the Pilgrim';
      case 134: return 'Relentless Gladiator %s';
      case 135: return 'Grand Crusader %s';
      case 136: return '%s the Argent Defender';
      default : return '%s';
    }
  }
  
  function title322_bad($TitleId) {
    switch ($TitleId) {
      case 0  : return '%s';
      case 1  : return 'Private %s';
      case 2  : return 'Corporal %s';
      case 3  : return 'Sergeant %s';
      case 4  : return 'Master Sergeant %s';
      case 5  : return 'Sergeant Major %s';
      case 6  : return 'Knight %s';
      case 7  : return 'Knight-Lieutenant %s';
      case 8  : return 'Knight-Captain %s';
      case 9  : return 'Knight-Champion %s';
      case 10 : return 'Lieutenant Commander %s';
      case 11 : return 'Commander %s';
      case 12 : return 'Marshal %s';
      case 13 : return 'Field Marshal %s';
      case 14 : return 'Grand Marshal %s';
      case 15 : return 'Scout %s';
      case 16 : return 'Grunt %s';
      case 17 : return 'Sergeant %s';
      case 18 : return 'Senior Sergeant %s';
      case 19 : return 'First Sergeant %s';
      case 20 : return 'Stone Guard %s';
      case 21 : return 'Blood Guard %s';
      case 22 : return 'Legionnaire %s';
      case 23 : return 'Centurion %s';
      case 24 : return 'Champion %s';
      case 25 : return 'Lieutenant General %s';
      case 26 : return 'General %s';
      case 27 : return 'Warlord %s';
      case 28 : return 'High Warlord %s';
      case 42 : return 'Gladiator %s';
      case 43 : return 'Duelist %s';
      case 44 : return 'Rival %s';
      case 45 : return 'Challenger %s';
      case 46 : return 'Scarab Lord %s';
      case 47 : return 'Conqueror %s';
      case 48 : return 'Justicar %s';
      case 53 : return '%s, Champion of the Naaru';
      case 62 : return 'Merciless Gladiator %s';
      case 63 : return '%s of the Shattered Sun';
      case 64 : return '%s, Hand of A\'dal';
      case 71 : return 'Vengeful Gladiator %s';
      case 72 : return 'Battlemaster %s';
      case 74 : return 'Elder %s';
      case 75 : return 'Flame Warden %s';
      case 76 : return 'Flame Keeper %s';
      case 77 : return '%s the Exalted';
      case 78 : return '%s the Explorer';
      case 79 : return '%s the Diplomat';
      case 80 : return 'Brutal Gladiator %s';
      case 81 : return '%s the Seeker';
      case 82 : return 'Arena Master %s';
      case 83 : return 'Salty %s';
      case 84 : return 'Chef %s';
      case 85 : return '%s the Supreme';
      case 86 : return '%s of the Ten Storms';
      case 87 : return '%s of the Emerald Dream';
      case 89 : return 'Prophet %s';
      case 90 : return '%s the Malefic';
      case 91 : return 'Stalker %s';
      case 92 : return '%s of the Ebon Blade';
      case 93 : return 'Archmage %s';
      case 94 : return 'Warbringer %s';
      case 95 : return 'Assassin %s';
      case 96 : return 'Grand Master Alchemist %s';
      case 97 : return 'Grand Master Blacksmith %s';
      case 98 : return 'Iron Chef %s';
      case 99 : return 'Grand Master Enchanter %s';
      case 100: return 'Grand Master Engineer %s';
      case 101: return 'Doctor %s';
      case 102: return 'Grand Master Angler %s';
      case 103: return 'Grand Master Herbalist %s';
      case 104: return 'Grand Master Scribe %s';
      case 105: return 'Grand Master Jewelcrafter %s';
      case 106: return 'Grand Master Leatherworker %s';
      case 107: return 'Grand Master Miner %s';
      case 108: return 'Grand Master Skinner %s';
      case 109: return 'Grand Master Tailor %s';
      case 110: return '%s of Quel\'Thalas';
      case 111: return '%s of Argus';
      case 112: return '%s of Khaz Modan';
      case 113: return '%s of Gnomeregan';
      case 114: return '%s the Lion Hearted';
      case 115: return '%s, Champion of Elune';
      case 116: return '%s, Hero of Orgrimmar';
      case 117: return 'Plainsrunner %s';
      case 118: return '%s of the Darkspear';
      case 119: return '%s the Forsaken';
      case 120: return '%s the Magic Seeker';
      case 121: return 'Twilight Vanquisher %s';
      case 122: return '%s, Conqueror of Naxxramas';
      case 123: return '%s, Hero of Northrend';
      case 124: return '%s the Hallowed';
      case 125: return 'Loremaster %s';
      case 126: return '%s of the Alliance';
      case 127: return '%s of the Horde';
      case 128: return '%s the Flawless Victor';
      case 129: return '%s, Champion of the Frozen Wastes';
      case 130: return 'Ambassador %s';
      case 131: return '%s the Argent Champion';
      case 132: return '%s, Guardian of Cenarius';
      case 133: return 'Brewmaster %s';
      case 134: return 'Merrymaker %s';
      case 135: return '%s the Love Fool';
      case 137: return 'Matron %s';
      case 138: return 'Patron %s';
      case 139: return 'Obsidian Slayer %s';
      case 140: return '%s of the Nightfall';
      case 141: return '%s the Immortal';
      case 142: return '%s the Undying';
      case 143: return '%s Jenkins';
      case 144: return 'Bloodsail Admiral %s';
      case 145: return '%s the Insane';
      case 146: return '%s of the Exodar';
      case 147: return '%s of Darnassus';
      case 148: return '%s of Ironforge';
      case 149: return '%s of Stormwind';
      case 150: return '%s of Orgrimmar';
      case 151: return '%s of Sen\'jin';
      case 152: return '%s of Silvermoon';
      case 153: return '%s of Thunder Bluff';
      case 154: return '%s of the Undercity';
      case 155: return '%s the Noble';
      case 156: return 'Crusader %s';
      case 157: return 'Deadly Gladiator %s';
      case 158: return '%s, Death\'s Demise';
      case 159: return '%s the Celestial Defender';
      case 160: return '%s, Conqueror of Ulduar';
      case 161: return '%s, Champion of Ulduar';
      case 163: return 'Vanquisher %s';
      case 164: return 'Starcaller %s';
      case 165: return '%s the Astral Walker';
      case 166: return '%s, Herald of the Titans';
      case 167: return 'Furious Gladiator %s';
      case 168: return '%s the Pilgrim';
      case 169: return 'Relentless Gladiator %s';
      case 170: return 'Grand Crusader %s';
      case 171: return '%s the Argent Defender';
      default : return '%s';
    }
  }
  
  function map322 ($MapId) {
    switch ($MapId) {
      case 0  : return "Eastern Kingdoms";
      case 1  : return "Kalimdor";
      case 13 : return "Testing";
      case 25 : return "Scott Test";
      case 29 : return "CashTest";
      case 30 : return "Alterac Valley";
      case 33 : return "Shadowfang Keep";
      case 34 : return "Stormwind Stockade";
      case 35 : return "<unused>StormwindPrison";
      case 36 : return "Deadmines";
      case 37 : return "Azshara Crater";
      case 42 : return "Collin's Test";
      case 43 : return "Wailing Caverns";
      case 44 : return "<unused> Monastery";
      case 47 : return "Razorfen Kraul";
      case 48 : return "Blackfathom Deeps";
      case 70 : return "Uldaman";
      case 90 : return "Gnomeregan";
      case 109: return "Sunken Temple";
      case 129: return "Razorfen Downs";
      case 169: return "Emerald Dream";
      case 189: return "Scarlet Monastery";
      case 209: return "Zul'Farrak";
      case 229: return "Blackrock Spire";
      case 230: return "Blackrock Depths";
      case 249: return "Onyxia's Lair";
      case 269: return "Opening of the Dark Portal";
      case 289: return "Scholomance";
      case 309: return "Zul'Gurub";
      case 329: return "Stratholme";
      case 349: return "Maraudon";
      case 369: return "Deeprun Tram";
      case 389: return "Ragefire Chasm";
      case 409: return "Molten Core";
      case 429: return "Dire Maul";
      case 449: return "Alliance PVP Barracks";
      case 450: return "Horde PVP Barracks";
      case 451: return "Development Land";
      case 469: return "Blackwing Lair";
      case 489: return "Warsong Gulch";
      case 509: return "Ruins of Ahn'Qiraj";
      case 529: return "Arathi Basin";
      case 530: return "Outland";
      case 531: return "Ahn'Qiraj Temple";
      case 532: return "Karazhan";
      case 533: return "Naxxramas";
      case 534: return "The Battle for Mount Hyjal";
      case 540: return "Hellfire Citadel: The Shattered Halls";
      case 542: return "Hellfire Citadel: The Blood Furnace";
      case 543: return "Hellfire Citadel: Ramparts";
      case 544: return "Magtheridon's Lair";
      case 545: return "Coilfang: The Steamvault";
      case 546: return "Coilfang: The Underbog";
      case 547: return "Coilfang: The Slave Pens";
      case 548: return "Coilfang: Serpentshrine Cavern";
      case 550: return "Tempest Keep";
      case 552: return "Tempest Keep: The Arcatraz";
      case 553: return "Tempest Keep: The Botanica";
      case 554: return "Tempest Keep: The Mechanar";
      case 555: return "Auchindoun: Shadow Labyrinth";
      case 556: return "Auchindoun: Sethekk Halls";
      case 557: return "Auchindoun: Mana-Tombs";
      case 558: return "Auchindoun: Auchenai Crypts";
      case 559: return "Nagrand Arena";
      case 560: return "The Escape From Durnholde";
      case 562: return "Blade's Edge Arena";
      case 564: return "Black Temple";
      case 565: return "Gruul's Lair";
      case 566: return "Eye of the Storm";
      case 568: return "Zul'Aman";
      case 571: return "Northrend";
      case 572: return "Ruins of Lordaeron";
      case 573: return "ExteriorTest";
      case 574: return "Utgarde Keep";
      case 575: return "Utgarde Pinnacle";
      case 576: return "The Nexus";
      case 578: return "The Oculus";
      case 580: return "The Sunwell";
      case 582: return "Transport: Rut'theran to Auberdine";
      case 584: return "Transport: Menethil to Theramore";
      case 585: return "Magister's Terrace";
      case 586: return "Transport: Exodar to Auberdine";
      case 587: return "Transport: Feathermoon Ferry";
      case 588: return "Transport: Menethil to Auberdine";
      case 589: return "Transport: Orgrimmar to Grom'Gol";
      case 590: return "Transport: Grom'Gol to Undercity";
      case 591: return "Transport: Undercity to Orgrimmar";
      case 592: return "Transport: Borean Tundra Test";
      case 593: return "Transport: Booty Bay to Ratchet";
      case 594: return "Transport: Howling Fjord Sister Mercy (Quest)";
      case 595: return "The Culling of Stratholme";
      case 596: return "Transport: Naglfar";
      case 597: return "Craig Test";
      case 598: return "Sunwell Fix (Unused)";
      case 599: return "Halls of Stone";
      case 600: return "Drak'Tharon Keep";
      case 601: return "Azjol-Nerub";
      case 602: return "Halls of Lightning";
      case 603: return "Ulduar";
      case 604: return "Gundrak";
      case 605: return "Development Land (non-weighted textures)";
      case 606: return "QA and DVD";
      case 607: return "Strand of the Ancients";
      case 608: return "Violet Hold";
      case 609: return "Ebon Hold";
      case 610: return "Transport: Tirisfal to Vengeance Landing";
      case 612: return "Transport: Menethil to Valgarde";
      case 613: return "Transport: Orgrimmar to Warsong Hold";
      case 614: return "Transport: Stormwind to Valiance Keep";
      case 615: return "The Obsidian Sanctum";
      case 616: return "The Eye of Eternity";
      case 617: return "Dalaran Sewers";
      case 618: return "The Ring of Valor";
      case 619: return "Ahn'kahet: The Old Kingdom";
      case 620: return "Transport: Moa'ki to Unu'pe";
      case 621: return "Transport: Moa'ki to Kamagua";
      case 622: return "Transport: Orgrim's Hammer";
      case 623: return "Transport: The Skybreaker";
      case 624: return "Vault of Archavon";
      case 628: return "Isle of Conquest";
      case 641: return "Transport: Alliance Airship BG";
      case 642: return "Transport: HordeAirshipBG";
      case 647: return "Transport: Orgrimmar to Thunder Bluff";
      case 649: return "Trial of the Crusader";
      case 650: return "Trial of the Champion";
      default : return "Unknown Map";
    }
  }

 /* Other */
  function get_usr_id($name) {
    $names = strtolower($name);
    $names[0] = strtoupper($names[0]);
    
    $return = @mysql_query('SELECT `guid` FROM `'.DB_CHR.'`.`characters` WHERE `name`="'.$names.'" LIMIT 1');
    $data = @mysql_fetch_assoc($return);
    
    if($data['guid'] == null)
      return false;
    else
      return $data['guid'];
  }
  
  function get_usr_record($user_id) {
    $return = @mysql_query('SELECT * FROM `'.DB_CHR.'`.`characters` WHERE `guid`='.$user_id.' LIMIT 1');
    $record = @mysql_fetch_assoc($return);
    
    if($record['guid'] == null)
      return false;
    else
      return $record;
  }
  
  function get_usr_data($user_id, $index) {
    $return = @mysql_query('SELECT `data` FROM `'.DB_CHR.'`.`characters` WHERE `guid`='.$user_id.' LIMIT 1');
    $datas = @mysql_fetch_assoc($return);
    if($datas['data'] == null) return false;
    
    $exp = explode(' ', $datas['data']);
    return $exp[$index];
  }
  
  function convert_date($stamp = null, $pattern = 'dc hc Mc Sc') {
    if($stamp == null) $stamp = time();
    $stamp = abs($stamp);
    $date[0] = floor($stamp/(24*60*60)); $stamp -= $date[0]*(24*60*60);
    $date[1] = floor($stamp/(60*60));    $stamp -= $date[1]*(60*60);
    $date[2] = floor($stamp/(60));       $stamp -= $date[2]*(60);
    $date[3] = $stamp;
    
    $rep['d'] = $date[0];  $rep['D'] = $date[0] >= 10 ? $date[0] : '0'.$date[0];
    $rep['h'] = $date[1];  $rep['H'] = $date[1] >= 10 ? $date[1] : '0'.$date[1];
    $rep['m'] = $date[2];  $rep['M'] = $date[2] >= 10 ? $date[2] : '0'.$date[2];
    $rep['s'] = $date[3];  $rep['S'] = $date[3] >= 10 ? $date[3] : '0'.$date[3];
    
    $symbs = array('dc', 'dn', 'hc', 'hn', 'mc', 'mn', 'sc', 'sn', 'Dc', 'Dn', 'Hc', 'Hn', 'Mc', 'Mn', 'Sc', 'Sn');
    $targs = array($rep['d'].'d', $rep['d'], $rep['h'].'h', $rep['h'], $rep['m'].'m', $rep['m'], $rep['s'].'s', $rep['s'], $rep['D'].'d', $rep['D'], $rep['H'].'h', $rep['H'], $rep['M'].'m', $rep['M'], $rep['S'].'s', $rep['S']);
    
    return str_replace($symbs, $targs, $pattern);
  }
  
  function convert_gold($money) {
    $gold = floor($money / 10000);
    $silv = floor($money / 100)-($gold*100);
    $coop = $money-($gold*10000)-($silv*100);
    
    return $gold.'g '.$silv.'s '.$coop.'c';
  }
?>